package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Handler;

@Controller
public class LoginController {

//    @RequestMapping("/login")
//    public Object login(@RequestBody JSONObject objectUser, HttpSession session){
//        System.out.println(123);
//        String username = objectUser.getString("username");
//        String password = objectUser.getString("password");
//        Map<Object, Object> map = new HashMap<>();
//
//        if(username.equals("admin") && password.equals("123456")){
//            map.put("code",0);
//            session.setAttribute("username",username);
//        }
//        else{
//            map.put("code",1);
//        }
//        return map;
//    }

    @RequestMapping("/login")
    public String loginPage(){
        return "login";
    }

    @RequestMapping("/login-error")
    public String errorMsg(Model model) {
        model.addAttribute("loginError", true);
        model.addAttribute("errorMsg", "账号密码错误");
        return "login";
    }
}
